home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include "data.h"
-
- #define HUGE 999999999.0
-
- struct atom *freeAtoms(struct atom *p)
- {
- if (p) {
- freeAtoms(p->next);
- free(p);
- }
- return NULL;
- }
-
- struct molecule *freeMolecules(struct molecule *p)
- {
- if (p) {
- p->atoms = freeAtoms(p->atoms);
- freeMolecules(p->next);
- free(p);
- }
- return NULL;
- }
-
- struct element *freeElements(struct element *p)
- {
- if (p) {
- freeElements(p->next);
- free(p);
- }
- return NULL;
- }
-
- struct element *createElement(struct element *p, char *name,
- float radius, float red, float green, float blue) {
-
- if (!p) {
- p = malloc(sizeof(struct element));
- strncpy(p->name, name, ELEMNAMESIZE);
- p->radius = radius;
- p->color = (int)(blue*255);
- p->color = p->color << 8;
- p->color |= (int)(green*255);
- p->color = p->color << 8;
- p->color |= (int)(red*255);
- p->next = NULL;
- }
- else
- if (strcmp(name, p->name))
- p->next = createElement(p->next, name, radius,
- red, green, blue);
- return p;
- }
-
- struct molecule *createMolecule(struct molecule *p, char *name) {
-
- if (!p) {
- p = malloc(sizeof(struct molecule));
- strncpy(p->name, name, MOLNAMESIZE);
- p->min[0] = p->min[1] = p->min[2] = HUGE;
- p->max[0] = p->max[1] = p->max[2] = 0;
- p->atoms = NULL;
- p->next = NULL;
- }
- else
- p->next = createMolecule(p->next, name);
- return p;
- }
-
- struct element *findElement(struct element *p, char *name)
- {
- if (p)
- if (strcmp(name, p->name) == 0)
- return p;
- else
- return findElement(p->next, name);
- else
- return NULL;
- }
-
- struct atom *createAtom(struct atom *p, struct element *e, float x, float y, float z) {
- if (!p) {
- p = malloc(sizeof(struct atom));
- p->e = e;
- p->xyz[0] = x;
- p->xyz[1] = y;
- p->xyz[2] = z;
- p->next = NULL;
- }
- else
- p->next = createAtom(p->next, e, x, y, z);
- return p;
- }
-
- void addAtom(struct molecule *p, char *name, float x, float y, float z) {
- float r;
- struct element *e = findElement(elementRoot, name);
- if (!e)
- error("Unknown element");
- if (!p)
- error("Data structure error--Can't add to NULL molecule");
- p->atoms = createAtom(p->atoms, e, x, y, z);
-
- r = e->radius;
- p->min[0] = MIN(p->min[0], x-r);
- p->min[1] = MIN(p->min[1], y-r);
- p->min[2] = MIN(p->min[2], z-r);
-
- p->max[0] = MAX(p->max[0], x+r);
- p->max[1] = MAX(p->max[1], y+r);
- p->max[2] = MAX(p->max[2], z+r);
- }
-
- error (char *s)
- {
- fprintf(stderr, "%s\n", s);
- exit(1);
- }
-
-